package com.example.base.tools

import android.content.Context
import android.os.Build

val Context.versionCode: Int
    get() {
        val packageManager = this.packageManager
        val packageInfo = packageManager.getPackageInfo(this.packageName, 0)
        @Suppress("DEPRECATION")
        (return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P)
            packageInfo.longVersionCode.toInt()
        else packageInfo.versionCode)
    }

val Context.versionName: String
    get() {
        val packageManager = this.packageManager
        val packageInfo = packageManager.getPackageInfo(this.packageName, 0)
        return packageInfo.versionName
    }